<template>
  <div>
    <el-select style="width: 100%"
               v-bind="$attrs"
               filterable
               clearable
               @input="handleInput"
               @focus="focus">
      <el-option v-for="item in typeOptions"
                 :key="item.goodsTypeId"
                 :disabled="!item.status"
                 :label="item.name"
                 :value="item.goodsTypeId + ''">
      </el-option>
    </el-select>
  </div>
</template>

<script>
import { goodsType } from "@/api/index";
export default {
  name: "SelectType",
  data () {
    return {
      typeOptions: []
    }
  },
  created () {
    this.search()
  },
  methods: {
    focus () {
      this.search()
      this.$emit("visibleOff", false);
    },
    handleInput (value) {
      this.$emit("input", value);
    },
    async search () {
      let { data } = await goodsType.search({ size: 1000 })
      this.typeOptions = data.records
    },
  }
}
</script>
